<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>商品管理</title>
    <meta name="description" content="这是一个商品管理页面">
    <meta name="keywords" content="商品管理">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" href="${contextPath}/assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="${contextPath}/assets/css/amazeui.datatables.min.css"/>
    <link rel="stylesheet" href="${contextPath}/assets/css/app.css">
    <script src="${contextPath}/assets/js/jquery.min.js"></script>
    <style>
        .am-u-sm-4{height:35px}
        .widget-body{margin-top: -20px}
    </style>
</head>

<body data-type="widgets">
<script src="${contextPath}/assets/js/theme.js"></script>
<div class="am-g tpl-g">
    <!-- 头部 -->
    <#include "/pc/common/header.html"/>
    <!-- 侧边导航栏 -->
    <#include "/pc/common/left.html"/>
    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <ol class="am-breadcrumb widget-head">
                            <li><a href="${contextPath}/index.htm" class="am-icon-home">首页</a></li>
                            <li>商品管理</li>
                            <li>商品查询</li>
                            <div class="am-btn-group-xs am-btn-group" style="float: right">
                                <button type="button" class="am-btn am-btn-secondary"
                                        onclick="search_b()"><span class="am-icon-search"></span>搜索
                                </button>
                                <a href="${contextPath}/product/list.htm" class="am-btn am-btn-warning">
                                    <span class="am-icon-refresh"></span>清空
                                </a>
                                <a href="${contextPath}/product/modify.htm" class="am-btn am-btn-default am-btn-success">
                                    <span class="am-icon-plus"></span> 新增
                                </a>
                            </div>
                        </ol>
                        <div class="widget-body  am-fr">
                            <div class="am-u-sm-12">
                                <div class="am-g">
                                    <div class="am-u-sm-4 am-form-inline">
                                        <label for="proname" class="am-form-label">商品名称：</label>
                                        <div class="am-form-group">
                                            <input type="text" class="am-form-field" id="proname"
                                                   placeholder="输入商品名称" value="${vo.proname!''}">
                                        </div>
                                    </div>
                                    <div class="am-u-sm-4 am-form-inline">
                                        <label for="online" class="am-form-label">上架状态：</label>
                                        <div class="am-form-group ">
                                            <select id="online" class="am-form-field" style="width: 185px;color: #a4a4a4;"
                                                    name="online">
                                                <option value="">请选择</option>
                                                <#if vo.online??>
                                                    <#assign online="${vo.online?c}" />
                                                </#if>
                                                ${dict.getOptions('product_online',online)}
                                            </select>
                                        </div>
                                    </div>
                                    <div class="am-u-sm-4 am-form-inline am-u-end">
                                        <label for="protype" class="am-form-label ">商品类型：</label>
                                        <div class="am-form-group">
                                            <select id="protype" class="am-form-field" style="width: 185px;color: #a4a4a4;"
                                                    name="online">
                                                <option value="">请选择</option>
                                                <#if vo.protype??>
                                                    <#assign protype="${vo.protype?c}" />
                                                </#if>
                                                ${dict.getOptions('product_protype',protype)}
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-12" style="border-top: 1px solid #eef1f5;padding-top: 10px;margin-top: 10px">
                                <table width="100%"
                                       class="am-table am-table-compact am-table-striped tpl-table-black am-text-nowrap am-scrollable-horizontal am-table-centered"
                                       id="example-r">
                                    <thead>
                                    <tr>
                                        <th width="">商品图片</th>
                                        <th width="">商品名称</th>
                                        <th width="">商品原价</th>
                                        <th width="">商品现价</th>
                                        <th width="">上架状态</th>
                                        <th width="">商品类型</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <#if page??>
                                    <#list page as l>
                                        <tr class="gradeX">
                                            <td><#if l.smimg??>
                                                <img src="${l.smimg}" class="tpl-table-line-img" alt=""
                                                     width="40" height="30">
                                            </#if></td>
                                            <td><a href="${contextPath}/product/detail.htm?id=${l.id!}">${l.proname!''}</a></td>
                                            <td>${l.oldprice!''}<small>元</small></td>
                                            <td>${l.price!''}<small>元</small></td>
                                            <td><#if l.online??>${dict.getDicName("product_online",l.online?c)}</#if></td>
                                            <td><#if l.protype??>${dict.getDicName("product_protype",l.protype?c)}</#if></td>
                                            <td>
                                                <div class="tpl-table-black-operation">
                                                    <a href="${contextPath}/product/modify.htm?id=${l.id!}">
                                                        <i class="am-icon-pencil"></i> 修改
                                                    </a>
                                                    <a href="javascript:;" onclick="to_special_b(${l.id!})" class="tpl-table-black-operation-set" style="cursor: pointer"
                                                       data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0, width: 400}">
                                                        推荐/引流
                                                    </a>
                                                    <#if l.online?? && l.online==1>
                                                        <a href="javascript:;" onclick="active_b(${l.id!},0)" class="tpl-table-black-operation-del">
                                                            <i class="am-icon-toggle-off"></i> 下架
                                                        </a>
                                                        <#elseif l.online?? && l.online==0>
                                                            <a href="javascript:;" onclick="active_b(${l.id!},1)" class="tpl-table-black-operation-change">
                                                                <i class="am-icon-toggle-on"></i> 上架
                                                            </a>
                                                    </#if>
                                                </div>
                                            </td>
                                        </tr>
                                    </#list>
                                    </#if>
                                    </tbody>
                                </table>
                            </div>
                            <#include "/pc/common/page.html">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1">
    <div class="am-modal-dialog">
        <div class="am-panel am-panel-default" style="margin-bottom:0">
            <div class="am-panel-hd">
                推荐/引流商品设置
                <a href="javascript: void(0)" style="float: right;" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <div class="am-panel-bd">
                <div style="width: 50%;margin: auto;">
                    <label class="am-checkbox">
                        <input type="checkbox" id="type1" value="" data-am-ucheck>
                        设置为引流商品
                    </label>
                    <label class="am-checkbox">
                        <input type="checkbox" id="type2" value="" data-am-ucheck>
                        设置为推荐商品
                    </label>
                    <button type="button" class="am-btn am-btn-primary" pid="" onclick="save_special_b(this)">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>
<#include "/pc/common/alert.html" />
<script src="${contextPath}/assets/js/amazeui.min.js"></script>
<script src="${contextPath}/assets/js/amazeui.datatables.min.js"></script>
<script src="${contextPath}/assets/js/dataTables.responsive.min.js"></script>
<script src="${contextPath}/assets/js/amazeui.page.js"></script>
<script src="${contextPath}/assets/js/app.js"></script>
<script>
    var to_special_b = function(id){
        $("#doc-modal-1 button").attr("pid",id);
        $.ajax({
            url: "${contextPath}/product/toSpecial.htm?id=" + id,
            type: "get",
            dataType: "json",
            success: function (data) {
                var json = $.parseJSON(data);
                if(json.type1){
                    $("#type1").uCheck('check');
                }else{
                    $("#type1").uCheck('uncheck');
                }
                if(json.type2){
                    $("#type2").uCheck('check');
                }else{
                    $("#type2").uCheck('uncheck');
                }
            }
        });
    }
    function save_special_b(obj){
        var pid = $(obj).attr("pid");
        var type1 = false;
        var type2 = false;
        if($("#type1").is(':checked')) {
            type1 = true;
        }
        if($("#type2").is(':checked')) {
            type2 = true;
        }
        $.ajax({
            url: "${contextPath}/product/saveSpecial.htm?id=" + pid+"&type1="+type1+"&type2="+type2,
            type: "get",
            dataType: "json",
            success: function (data) {
                var json = $.parseJSON(data);
                if(json.isSuccess){
                    $("#doc-modal-1").modal('close');
                }
                Malert(json.errMessage);
            }
        });
    }
    var search_b = function () {
        var proname = $("#proname").val();
        var online = $("#online").val();
        var protype = $("#protype").val();
        location.href = "${contextPath}/product/list.htm?proname=" + proname + "&online=" + online + "&protype=" + protype;
    }
    function active_b(id, online) {
        var msg = "你确定要上架这个商品吗？";
        if (online == 0) {
            msg = "你确定要下架这个商品吗？";
        }
        Mconfirm(msg, function () {
            $.ajax({
                url: "${contextPath}/product/active.htm?id=" + id + "&online=" + online,
                type: "get",
                dataType: "json",
                success: function (data) {
                    var json = $.parseJSON(data);
                    Malert(json.errMessage, function () {
                        location.reload();
                    });
                }
            });
        });
    }
</script>
</body>

</html>